package com.lvyq.myplayer.widget

import android.content.Context
import android.graphics.drawable.AnimationDrawable
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import com.lvyq.myplayer.R
import com.lvyq.myplayer.base.BaseActivity
import com.lvyq.myplayer.common.shared.MainAudioSharedPrefsManager
import com.lvyq.myplayer.common.util.DataOperationUtils
import com.lvyq.myplayer.parcelable.SongInfoData
import org.jetbrains.anko.find

/**
 * 文件描述：AudioListItemView
 * 作者：lvyq
 * 创建时间：2025-03-11
 * 修改时间：2025-03-11
 */
class AudioListItemView:RelativeLayout {

    lateinit var song:TextView
    lateinit var singer:TextView

    lateinit var playIngImg:AnimationDrawable
    lateinit var playImg:ImageView
    lateinit var playDel:ImageView


     constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    init {
        View.inflate(context, R.layout.item_play_list,this)
        song = findViewById<TextView>(R.id.song)
        singer = findViewById<TextView>(R.id.singer)
        playImg=findViewById<ImageView>(R.id.playIngImg)
        playIngImg= playImg.drawable as AnimationDrawable
        playDel=find(R.id.playDel)
    }

    fun setData(data: SongInfoData) {
        singer.setText(data.singer)
        song.setText(data.position.toString()+"."+data.title)
        //判断是否播放中
        var currentAudioId = MainAudioSharedPrefsManager.getCurrentAudioPosition(context)
        if (currentAudioId==data.position.toString()){
                playImg.visibility= VISIBLE
                playIngImg.start()
        }else{
            playImg.visibility= GONE
            playIngImg.stop()
        }

    }





}